import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:niu_app/configs/app_style_config.dart';
import 'package:niu_app/views/jk/jk_text.dart';
class EditHomePage extends StatefulWidget {
  @override
  _EditHomePageState createState() => _EditHomePageState();
}

class _EditHomePageState extends State<EditHomePage> {
  String headImagePath;
  String bgImagePath;


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text("编辑主页"),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 16.w),
        child:ListView(
          children: [
            ImageCell(
              title: "头像",
              image: headImagePath==null?NetworkImage("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3831697775,1952018276&fm=26&gp=0.jpg",):
                  FileImage(File(headImagePath),
                  ),
            ),
            ImageCell(
              title: "背景",
              image: bgImagePath == null
                  ? NetworkImage(
                "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3831697775,1952018276&fm=26&gp=0.jpg",
              )
                  : FileImage(
                File(headImagePath),
              ),
            ),
            TextCell(title: "性别", value: "男"),
            TextCell(title: "城市", value: "广东/珠海"),
            SignatureCell(),
          ],
        ),

      ),
    );
  }
  Widget ImageCell({String title,ImageProvider image,Function handle}){
    return Container(
      height: 60.w,
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(
            width: 0.5,
            color:Colors.grey[200],
          )
        )
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          JKText(
            data: title??"",
            fontSize: 16.w,
            color: Color.fromRGBO(38, 38, 38, 1),
          ),
          GestureDetector(
            onTap: handle,
            child: Container(
              width: 40.w,
              height: 40.w,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(2.r)),
                image: DecorationImage(
                  image: image,
                  fit: BoxFit.cover
                )
              ),
            ),
          )
        ],
      ),
    );
  }
  Widget TextCell({String title, String value}){
    return Container(
      height: 60.h,
      padding: EdgeInsets.symmetric(vertical: 8.h),
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(
            width: 0.5,
            color: Colors.grey[200],
          ),
        ),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            title ?? "",
            style: TextStyle(
                color: Color.fromRGBO(38, 38, 38, 1),
                fontSize: 16.w,
                ),
          ),
          Text(
            value ?? "",
            style: TextStyle(
              color: AppStyleConfig.color2,
              fontSize: 16.w,
            ),
          ),
        ],
      ),
    );
  }
  Widget SignatureCell(){
    return Container(
      margin: EdgeInsets.only(top: 20.h),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "签名",
            style: TextStyle(
                color: Color.fromRGBO(38, 38, 38, 1),
                fontSize: 16.w,
                ),
          ),
          Container(
            margin: EdgeInsets.only(top: 20.h),
            padding: EdgeInsets.symmetric(vertical: 8.h),
            height: 200.h,
            decoration: BoxDecoration(
              border: Border.all(width: 0.5, color: Colors.grey[200]),
              borderRadius: BorderRadius.all(
                Radius.circular(4.w),
              ),
            ),
            child: TextField(
              keyboardType: TextInputType.multiline,
              style: TextStyle(fontSize: 14.sp),
              maxLines: 5,
              minLines: 1,
              cursorColor: AppStyleConfig.color2,
              decoration: const InputDecoration(
                  hintText: '请输入个性签名',
                  hintStyle: TextStyle(
                      fontSize: 14, color: Colors.grey),
                  filled: true,
                  fillColor: Colors.white,
                  contentPadding:
                  const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
                  isDense: true,
                  border: InputBorder.none),
            ),
          ),
        ],
      ),
    );
  }
  Widget ButtonCellWidget(){
    return Container(
      child: Row(
        children: [
          Expanded(
            flex: 1,
            child: Container(
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(
                    Radius.circular(4.r),
                  ),
                  color: AppStyleConfig.color2),
              alignment: Alignment(0, 0),
              child: Text(
                "取消",
                style: TextStyle(color: Colors.white, fontSize: 14.sp),
              ),
            ),
          ),
          SizedBox(
            width: 20.w,
          ),
          Expanded(
            flex: 1,
            child: Container(
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(
                    Radius.circular(4.r),
                  ),
                  color: AppStyleConfig.background),
              alignment: Alignment(0, 0),
              child: Text(
                "保存",
                style: TextStyle(color: Colors.white, fontSize: 14.sp),
              ),
            ),
          ),
        ],
      ),
    );
  }


}
